<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const s1 = Symbol()
    const s2 = Symbol()
    const obj = {
      [s1]: 'aaa',
      [s2]: 'bbb'
    }
    console.log(obj)

    const obj1 = {}
    obj1[s1] = 'aaa'
    obj1[s2] = 'bbb'
    console.log(obj1)

    const obj2 = {}
    Object.defineProperty(obj2, s1, {
      value: 'aaa',
    })
    Object.defineProperty(obj2, s2, {
      value: 'bbb',
    })
    console.log(obj2)

    // 2.获取Symbol对应的key
    console.log(Object.keys(obj))
    console.log(Object.getOwnPropertySymbols(obj))
    const symbolKeys = Object.getOwnPropertySymbols(obj)
    for (const key of symbolKeys) {
      console.log(key)
    }

    // 3.description
    // Symbol 函数直接生成的值,都是独一无二的
    const s3 = Symbol('ccc')
    console.log(s3.description) // 'ccc'
    const s4 = Symbol(s3.description)
    console.log(s3 === s4) // false
    const s5 = Symbol.for(s3.description)
    const s6 = Symbol.for(s3.description)
    console.log(s3 === s5) // false
    console.log(s5 === s6) // true

    // 获取传入的key
    console.log(Symbol.keyFor(s5)) // 'ccc'
    

  </script>
</body>

</html>